package com.example.p212propertysources;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {
    //1使用@Value注解：读取springboot全局配置文件单个配置。
    @Value("${user}")
    private String user;

    //使用Environment接口：通过Environment接口动态获取配置。（将yml全部数据封装到Environment对象）
    @Resource
    private Environment env;


    @GetMapping("/getvalue")
    public String getValue() {
        String password = env.getProperty("password");

        return "user: " + user + "\n"
                + "password: " + password + "\n"
                ;
    }


}
